//
//  TodayScheduleCell.m
//  EducationAdminClient
//
//  Created by 孙添凤 on 16/11/10.
//  Copyright © 2016年 周佳兴. All rights reserved.
//

#import "TodayScheduleCell.h"
#import "Masonry.h"
#import "UIColor+CL.h"
#import "EducationAdminClient_URL.h"
#import "BaseAllViewController.h"
@implementation TodayScheduleCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

-(instancetype)initWithReuseIdentifier:(NSString *)reuseIdentifier{
    
    self = [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
    if(self){
        
        UIView *v = [self createUI];
        // UIView要加入到self.contentView上 不要加入到self
        [self.contentView addSubview:v];
        UIView *superview = self.contentView;
        UIEdgeInsets edge = UIEdgeInsetsMake(0, 0, 0, 0);
        [v mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(superview).insets(edge);
        }];
        
    }
    return self;
}


-(UIView *)createUI{
    UIView *baseView = [[UIView alloc]init];
    baseView.backgroundColor =[UIColor colorWithHex:0xf7f7f7];
    UIView *v= [[UIView alloc]init];
    [baseView addSubview:v];
    [v mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(baseView.mas_top);
        make.left.equalTo(baseView.mas_left);
        make.right.equalTo(baseView.mas_right);
        make.bottom.equalTo(baseView.mas_bottom).offset(-7);
    }];
    v.backgroundColor =[UIColor whiteColor];
    
    _titleLa = [[UILabel alloc]init];
    [v addSubview:_titleLa];
    [_titleLa mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(v.mas_left).offset(16.5);
        make.centerY.equalTo(v.mas_centerY);
        make.width.equalTo(@(300));
        make.height.equalTo(@(20));
    }];
    _titleLa.backgroundColor =[UIColor clearColor];
    _titleLa.font =[UIFont systemFontOfSize:16];
    _titleLa.textColor =[UIColor colorWithHex:0x4c4c4c];
    

    
    
    _timeLa = [[UILabel alloc]init];
    [v addSubview:_timeLa];
    [_timeLa sizeToFit];
    [_timeLa mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(v.mas_right).offset(-16.5);
        make.centerY.equalTo(v.mas_centerY);
        make.width.equalTo(@(200));
        make.height.equalTo(@(16));
    }];
    _timeLa.textAlignment = NSTextAlignmentRight;
    _timeLa.backgroundColor =[UIColor clearColor];
    _timeLa.font =[UIFont systemFontOfSize:16];
    _timeLa.textColor =[UIColor colorWithHex:0x858585];
    //这里添加功能判断
    if (getEnglishLanguage()) {
        _titleLa.text = @"No Data";
        _timeLa.text = @"No Data";
    }else{
        _titleLa.text = @"暂无数据";
        _timeLa.text = @"暂无数据";
    }
    
    
    return baseView;
}


-(void)setCnName:(NSMutableArray *)cnName{
    
    NSLog(@"%@",cnName);
    BOOL isHaveEnglishName = NO;
    NSString *EnglishNameStr = [[NSString alloc] init];
    for (NSDictionary *stuNameDic in cnName) {
        
        if ([[stuNameDic objectForKey:@"fieldCnName"] isEqualToString:@"学员名称"]) {
            isHaveEnglishName = YES;
            EnglishNameStr = [stuNameDic objectForKey:@"fieldAliasName"];
            break;
        }
    }
    //将来英文版需要修改学员名称就改这里⬇️⬆️看板页左右结构
    _titleLa.text = [NSString stringWithFormat:@"%@",[_dic objectForKey:EnglishNameStr]];
    if(cnName.count>3){
    NSString *str = [cnName[3] objectForKey:@"fieldAliasName"];
        
        NSLog(@"%@",_dic);
    NSString *content =[_dic objectForKey:str];
    NSArray *arr = [content componentsSeparatedByString:@","];
        NSArray *arr2;
        if (arr.count>1) {
            arr2 = [arr[1]componentsSeparatedByString:@":"];
        }
        NSArray *arr3;
        if (arr.count>0) {
            arr3 = [arr[0]componentsSeparatedByString:@"_"];
        }
     
    if([arr2[0] isEqualToString:@"班号"]){
        if (arr3.count>1) {
            _titleLa.text = arr3[1];
        }
      
    }else{
        //这里添加功能判断
        if (getEnglishLanguage()) {
            if (isHaveEnglishName) {
                if ([_dic objectForKey:EnglishNameStr]) {
                    _titleLa.text = [_dic objectForKey:EnglishNameStr];
                }else{
                    _titleLa.text = @"NO Data";
                }
                
            }else{
                if (arr2.count > 1) {
                    _titleLa.text = arr2[1];
                }
            }
        }else{
            if (arr2.count > 1) {
                _titleLa.text = arr2[1];
            }
        }

        
        
      
    }
    NSString *str1 = [_dic objectForKey:[cnName[1] objectForKey:@"fieldAliasName"]];
    _timeLa.text = str1;
    }else{
        _titleLa.text =[_dic objectForKey:[cnName[0] objectForKey:@"fieldAliasName"]];
        if ([_dic objectForKey:[cnName[1] objectForKey:@"fieldAliasName"]]) {
            NSLog(@"对喽");
            _timeLa.text =[NSString stringWithFormat:@"%@",[_dic objectForKey:[cnName[1] objectForKey:@"fieldAliasName"]]];
        }else{
            NSLog(@"GG");
            _timeLa.text =[NSString stringWithFormat:@"%@",@"0"];
        }
        

    }
}

-(void)setDic:(NSDictionary *)dic{
    _dic = dic;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
